
const http = require("http");

const app = http.createServer((req,res) => {

    res.writeHead(200,{
        "Content-Type":"text/plain",
        "Access-Control-Allow-Origin":"*", // 设置允许访问的源，* 表示所有源都可以
        "Access-Control-Allow-Mathods":"GET,PUT,DELETE",
        "Access-Control-Allow-Headers":"X-Custom-Header",
        "Access-Control-Max-Age":2000, // 指定预检请求的有效期，单位为秒
        // "Access-Control-Allow-Credentials":true

    })

    let resData = {},
        postData = [];

    req.on('data',chunk => {
        postData.push(chunk);
    })

    req.on('end',() => {


        resData.postData = Buffer.concat(postData).toString();
        res.end(JSON.stringify(resData));
    })
});


app.listen(3000,() => {
    console.log('应用已启动');
})